package com.example.fw;

import org.hibernate.Session;
import org.hibernate.Transaction;

import com.example.tests.ContactData;
import com.example.tests.GroupData;
import com.example.utils.SortedListOf;

public class HibernateHelper extends HelperBase
{

	public HibernateHelper(ApplicationManager manager)
	{
		super(manager);
	}

	public SortedListOf<GroupData> getGroups()
	{
		Session session = HibernateUtil.getSessionFactory().getCurrentSession();
		Transaction trans = session.beginTransaction();
		try
		{
			return new SortedListOf<GroupData>(
					session.createQuery("from GroupData").list());
		}
		finally
		{
			trans.commit();
		}
	}

	public SortedListOf<ContactData> getContacts()
	{
		Session session = HibernateUtil.getSessionFactory().getCurrentSession();
		Transaction trans = session.beginTransaction();
		try
		{
			return new SortedListOf<ContactData>(
					session.createQuery("from ContactData").list());
		}
		finally
		{
			trans.commit();
		}
	}
}